<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;

use app\admin\model\ComValidate;
use app\admin\model\ComModel;


class Banner extends Common{

	public function _initialize(){
		if(request()->isGet()){

			$action= strtolower ( Request::instance()->action() );

			switch ($action) {
		
				case 'bannerlist':
					$this->assign('title',"轮播列表");
					$controller="banner";
					break;
				case 'bannerinfo':
					$this->assign('title',"轮播信息");
					$controller="banner";
					break;
			}

			$this->assign('controller',$controller);
		}
	}

	#banner列表#
	public function bannerlist(){

		if(request()->isGet()){

			$this->log("banner列表");
			
			return $this->fetch();
		}

	}
	#banner列表接口#
	public function jsonbannerlist(){
		
			$page=input('page');
			$limit=input('limit');

			$start=input('start');
			$end=input('end');

			if($start){
				$map['addtime']=array('egt',$start);
			}
			if($end){
				$map['addtime']=array('elt',$end);
			}
			if($start&&$end){
				$map['addtime']=array('between',$start.",".$end);
			}

			$list=Db::name('banner_list')->page($page.','.$limit)->where($map)->order('px desc')->select();
			
			foreach ($list as $key => $v) {

				$list[$key]['src']=adminthumb($v['src']);

				if($v['status']=='1'){
					$list[$key]['status']="<span class='layui-badge-rim layui-bg-green'>正常</span>";
				}else{
					$list[$key]['status']="<span class='layui-badge-rim layui-bg-gray'>下架</span>"; 
				}
			}
			$count=Db::name('banner_list')->count('bannerid');

			$arr=array(
				'code'=>"0",
				'count'=>$count,
				'data'=>$list
			);
			return json($arr);
			//json($list);
	}

	#编辑banner信息#
	public function bannerinfo(){

		if(request()->isGet()){

			$bannerid=input('bannerid');
		
			if($bannerid){

				$this->assign('info',ComModel::data_find('banner_list',['bannerid'=>$bannerid]));
			}

			$this->assign('videocate',$videocate);
			return $this->fetch();

		}else{

			$this->log("编辑banner信息");

			$data=input('post.');
	
			$data['status']=empty($data['status'])?"0":$data['status'];

			unset($data['file']);

			//修改
			if($data['bannerid']){

				ComModel::data_up("banner_list",$data,url('bannerlist'));

			//添加
			}else{

				ComModel::data_add("banner_list",$data,url('bannerlist'));
			}
		}
	}
	#删除banner#
	public function bannerdel(){

		$this->log("删除banner");

		$bannerid=input('bannerid');

		echo ComModel::data_del('banner_list',['bannerid'=>$bannerid]);
	}


}